package com.zd.controller;/**
 * @Description: SignlistController
 * @Author:pioneer
 * @Date: 2021-07-14
 * @Version:v1.0
 */

import com.mysql.cj.Session;
import com.zd.service.lnter.*;
import com.zzg.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: SignlistController
 * @Author:pioneer
 * @Date: 2021-07-14
 * @Version:v1.0
 */
@Controller
public class SignlistController {

    @Autowired
    private SignlistZdServicelnter signlistZdServicelnter;
    @Autowired
    private ConsigneeServicelnter consigneeServicelnter;
    @Autowired
    private WaybillServicelnter waybillServicelnter;
    @Autowired
    private SubstationServicelnter substationServicelnter;
    @Autowired
    private WaybillstateServicelnter waybillstateServicelnter;
    @Autowired
    private TailafterServicelnter tailafterServicelnter;

    /**
     * 查询签收列表的所有信息
     * @param page 页码
     * @param limit 条目数
     * @return 签收map集合
     */
    @RequestMapping("querySignlist")
    @ResponseBody
    public Map<String,Object> querySignlist(int page, int limit){
        System.out.println ("querySignlist进：page"+page+"\tlimit"+limit);
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",signlistZdServicelnter.selectSignlist ().size ());
        map.put("data",signlistZdServicelnter.pagingquerySignlist (page,limit));
        System.out.println (map);
        return map;
    }

    /**
     * 查询所有运单信息
     * @return 运单集合
     */
    @RequestMapping("getWaybilltype")
    @ResponseBody
    public List<Waybill> getWaybilltype(){
        List<Waybill> waybillList=waybillServicelnter.selectWaybill ();
        System.out.println ("waybillList:\t"+waybillList);
        return waybillList;
    }

    /**
     * 查询所有收货人信息
     * @return 收货人集合
     */
    @RequestMapping("getReceivingunit")
    @ResponseBody
    public List<Consignee> getReceivingunit(){
        List<Consignee> consigneeList=consigneeServicelnter.selectConsignee ();
        System.out.println ("querySignlist:\t"+consigneeList);
        return consigneeList;
    }

    /**
     * 查询所有分站信息
     * @return 分站集合
     */
    @RequestMapping("getsubserieslist")
    @ResponseBody
    public List<Substation> getsubserieslist(){
        List<Substation> substationList= substationServicelnter.selectSubstation ();
        System.out.println ("getsubserieslist:\t"+substationList);
        return substationList;
    };

    /**
     * 根据运单号查询签收信息详细
     * @return 分站集合
     */
    @RequestMapping("getSignlist")
    @ResponseBody
    public Departurelist getSignlist(String checkenumber){
        System.out.println ("进"+checkenumber);
        Departurelist departurelist=signlistZdServicelnter.getSignlistByid (checkenumber);
        System.out.println ("getSignlist:\t"+departurelist);
        return departurelist;
    };

    /**
     * 多条件查询签收列表信息所有信息
     * @return map集合
     */
    @RequestMapping("conditionSignlist")
    @ResponseBody
    public Map<String,Object> conditionSignlist(Departurelist departurelist){
        int page=1;
        int limit=10;
        Map<String,Object> map = new HashMap<> ();
        map.put("code","");
        map.put("msg","");
        map.put("count",signlistZdServicelnter.getSignlistcondition (departurelist));
        map.put("data",signlistZdServicelnter.conditionquerySignlist (departurelist,page,limit));
        System.out.println (map);
        return map;
    }

    /**
     * 根据运单号快速签收
     * @param waybillnumber 运单id
     * @param response 返回
     * @throws IOException
     */
    @RequestMapping("quicksig")
    public void quicksig(String waybillnumber, HttpServletResponse response) throws IOException {
        System.out.println ("quicksig ：进"+waybillnumber);
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        if(waybillnumber!=null){
            int ser =waybillstateServicelnter.updatestateBy ("已签收",waybillnumber);
            System.out.println (ser);
            if(ser>=0){
                out.write("签收成功");
            }else{
                out.write("签收失败");
            }
        }
    }

    /**
     * 查询所有的运单状态
     * @return 运单集合
     */
    @RequestMapping("getTailafterlist")
    @ResponseBody
    public List<Tailafter> getTailafterlist(){
        List<Tailafter> tailafterList= tailafterServicelnter.getTailafterByid ();
        System.out.println ("getTailafterlist\t"+tailafterList);
        return tailafterList;
    }
}
